package zozopo.warehouse;

import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import zozopo.warehouse.operations.PurchaseOS;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class GetGoodsNumberForAjaxAction extends ActionSupport implements Action,SessionAware,ServletRequestAware,ServletResponseAware{
	//传入参数
	private int warehouseid;
	private int goodsid;

	//传出参数
	HttpServletRequest request;
	HttpServletResponse response;
	private Map<Object, Object> session;
	
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		request = arg0;
	}

	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}

	

	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		response = arg0;
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/xml; charset=UTF-8");
	}
	
	public String execute(){
		
		PurchaseOS purchaseOS = new PurchaseOS();
		
		try {
			int goodsReserve = purchaseOS.getGoodsReserve(warehouseid, goodsid);
			response.getWriter().write(goodsReserve+"");
			response.getWriter().flush();
			response.getWriter().close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		purchaseOS.releaseConnection();
		
		
		return NONE;
	}


	public void setGoodsid(int goodsid) {
		this.goodsid = goodsid;
	}

	public int getWarehouseid() {
		return warehouseid;
	}

	public void setWarehouseid(int warehouseid) {
		this.warehouseid = warehouseid;
	}

}
